package com.gxa.modules.pc.hospital.controller;

import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Result;
import com.gxa.modules.model.dto.PackageTypeDetailDto;
import com.gxa.modules.model.dto.PackageTypeDto;
import com.gxa.modules.pc.hospital.service.impl.PackageTypeServiceImpl;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.websocket.server.PathParam;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 套餐类型 前端控制器
 * </p>
 *
 * @author gxa
 * @since 2022-11-12 05:04:59
 */
@Slf4j
@Api(tags = "套餐类型")
@RestController
@RequestMapping("/pc/medicalCheck")
public class PackageTypeController {

    @Autowired
    private PackageTypeServiceImpl packageTypeService;
    @ApiOperation(value = "带条件的分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "page", value = "页数", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "size", value = "一页的数量", dataType = "Integer")
    })
    @PostMapping("/medicalCheck")
    public Result<Map> queryByPage (@RequestParam Integer page,Integer size){
        Map<String, Object> stringObjectMap = this.packageTypeService.queryAll(page, size);
        return new Result<Map>().ok(stringObjectMap);
    }

    @ApiOperation(value = "根据套餐类型id查询")
    @ApiImplicitParam(paramType = "path",name = "id",value ="套餐类型id",dataType ="Integer")
    @PostMapping("/medicalById/{id}")
    public Result<PackageTypeDto> queryById (@PathVariable("id") Integer id){
        try {
            PackageTypeDto packageTypeDto = this.packageTypeService.queryById(id);
            return new Result<PackageTypeDto>().ok(packageTypeDto);
        }catch (Exception e){
            e.printStackTrace();
            return new Result<PackageTypeDto>().error("查询失败");
        }
    }

    @ApiOperation(value = "根据套餐类型id删除")
    @ApiImplicitParam(paramType = "body", name = "ids", value = "删除的id集合", dataType = "list")
    @DeleteMapping("/medicalById")
    public Result deleteById (@RequestBody List<Long> ids ){
        log.info("-----{}------",ids);
        try {
            this.packageTypeService.deleteById(ids);
            return new Result().ok("删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result().error("删除失败");
        }

    }

    @ApiOperation(value = "根据套餐类型id更改状态")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "query", name = "id", value = "套餐类型id", dataType = "Integer"),
        @ApiImplicitParam(paramType = "query", name = "state", value = "套餐类型状态", dataType = "Integer")
    })
    @PutMapping("/medicalById")
    public Result updateStateByid (@RequestParam Integer id,@RequestParam Integer state){
        try {
            this.packageTypeService.updateStateById(id, state);
            return new Result().ok("修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result<>().error("修改失败");
        }
    }


    @ApiOperation(value = "更新套餐类型详细信息")
    @ApiImplicitParam(paramType = "query",name = "id",value ="套餐类型id",dataType ="Integer")
    @PutMapping("/updateById")
    public Result updateById (@RequestBody PackageTypeDto packageTypeDto ){
        try {
            this.packageTypeService.updateByPackageTypeId(packageTypeDto);
            return new Result().ok("修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result().error("修改失败");
        }

    }
    @ApiOperation(value = "增加套餐类型")
    @PostMapping("/add")
    public Result add (@RequestBody PackageTypeDetailDto packageTypeDetailDto ){
        try {
            this.packageTypeService.add(packageTypeDetailDto);
            return new Result().ok("添加成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result().error("添加失败");
        }

    }



}
